<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    <title>薪酬标准管理</title>
    <!--引入本地的css样式-->
    <link rel="stylesheet" href="../../static/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../static/css/admin.css" media="all">
</head>
<style>
    /*搜索表单名字宽度*/
    .layui-form-label{
        width: 120px!important;
    }
    .layui-btn-sm{
        background-color: goldenrod;
    }

</style>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-form layui-card-header layuiadmin-card-header-auto" style="border-radius: 0;border-top: 4px solid #d2d2d2;">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">薪资标准名称名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="sal_standard_name" placeholder="请输入雇员名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">审核状态</label>
                <div class="layui-input-inline">
                    <select name="review_status">
                        <option value=""></option>
                        <option value="1">审核中</option>
                        <option value="2" selected="">审核通过</option>
                        <option value="3">驳回</option>
                        <option value="0">起草</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-emp-front-search">
                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                </button>
            </div>
        </div>
    </div>
</div>
<!--薪资标准表显示位置-->
<div class="layui-card">
    <div class="layui-card-body">
        <!--        添加标准-->
        <div style="padding-bottom: 10px;">
            <button class="layui-btn layuiadmin-btn-useradmin" data-type="add">标准登记</button>
        </div>
        <div class="layui-tab layui-tab-card">
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <table style="margin-top: 10px;" id="standard-table" lay-filter="standard-table"></table>
                </div>
            </div>
        </div>
        <script type="text/html" id="table-operation">
            {{#  if(d.review_status == 1){ }}
            <a class="layui-btn layui-btn-container layui-btn-xs" lay-event="review"><i class="layui-icon layui-icon-edge"></i>复核</a>
            {{#  } else if(d.review_status == 2) { }}
            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="change"><i class="layui-icon layui-icon-chart"></i>变更</a>
            {{#  } else if(d.review_status == 3) { }}
            {{#  } else if(d.review_status == 0) { }}
            <a class="layui-btn layui-btn-sm layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>修改</a>
            {{#  } }}
            <a class="layui-btn layui-btn-checked layui-btn-xs" lay-event="details"><i class="layui-icon layui-icon-about"></i>明细</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
        </script>
    </div>
</div>
</body>
<!--判断审核状态格式更改-->
<script type="text/html" id="review-status">
    {{#if (d.review_status == 1) { }}
    <span>审核中</span>
    {{# }else if(d.review_status == 2){ }}
    <span>审核通过</span>
    {{# }else if(d.review_status == 3){ }}
    <span>驳回</span>
    {{# }else if(d.review_status == 0){ }}
    <span>起草</span>
    {{# } }}
</script>

<!--时间日期格式更改-->
<script type="text/html" id="log-register-time">
    {{layui.util.toDateString(d.register_time,  "yyyy-MM-dd HH:mm:ss")}}
</script>

<script src="../../static/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['table','form','jquery','element','laydate'],function () {
        let $ = layui.jquery;
        let table = layui.table;
        let form = layui.form;
        let element = layui.element;
        var laydate = layui.laydate;

        //加载表
        table.render({
            elem: '#standard-table', //嘿嘿嘿
            url: '/standard/salFindAll', //接口
            page: true , //显示分页
            limits:[5,10,15,20,25], //分页范围
            cols :[  //表数据
                [
                    {title: '薪资标准编码', field: 'sal_standard_code', align:'center'},
                    {title: '薪资标准名称', field: 'sal_standard_name', align:'center'},
                    {title: '登记时间', field: 'register_time',templet:'#log-register-time', align:'center'},
                    {title: '审核状态', field: 'review_status', align:'center',templet:'#review-status'},
                    {title: '<div style="text-align: center;">操作</div>',align:'left',toolbar:'#table-operation'}
                ]]
        });

        form.on('submit(log-query)', function(data){
            //执行重载
            table.reload($('.layui-show').children()[0].id,{where:data.field})
            return false;
        });


        //监听搜索
        form.on('submit(LAY-emp-front-search)', function(data){
            var field = data.field;
            // 调用后端接口，传递参数
            table.reload('standard-table', {
                url:"/standard/search", //后端搜索接口URL地址
                where: field
            });
        });

        //监听标准登记事件
        var active = {
            add: function(){
                layer.open({
                    type: 2
                    ,title: '添加标准'
                    ,skin: 'layui-layer-molv'
                    ,content: 'standard/add.html'
                    ,maxmin: true
                    ,area: ['1000px', '666px']
                    ,btn: ['确定', '取消','申请复核']
                    ,yes: function(index, layero){
                        var iframeWindow = window['layui-layer-iframe'+ index]
                            ,submitID = 'LAY-user-front-submit'
                            ,submit = layero.find('iframe').contents().find('#'+ submitID);
                        //监听提交
                        iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                            var field = data.field; //获取提交的字段
                            $.ajax({
                                url:"/standard/salAdd", //请求后端接口地址
                                type:"post", //请求方式get | post
                                data:JSON.stringify(field), //提交json字符串对象参数
                                contentType:"application/json;charset=utf-8", //发送信息至服务器时内容编码类型
                                dataType:"json", //后端返回参数类型
                                success:function (res){ //请求成功后回调函数res = JSONObject.toJSONString(resultMap)
                                    if(res.code == 0){//成功
                                        layer.msg(res.msg);//弹出提示
                                        table.reload('standard-table'); //数据刷新
                                        layer.close(index); //关闭弹层
                                    }
                                    if(res.code == -1){//系统出问题
                                        layer.msg(res.msg,{icon: 5});//弹出提示
                                    }
                                }
                            })
                        });
                        submit.trigger('click');
                    }
                });
            }
        };
        //确认后数据更新
        $('.layui-btn.layuiadmin-btn-useradmin').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //监听行工具事件
        table.on('tool(standard-table)', function(obj){
            var data = obj.data;
            if(obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    $.ajax({
                        url: "/standard/salDel", //请求后端接口地址
                        type: "post", //请求方式get | post
                        data: {sal_standard_code: data.sal_standard_code}, //提交json字符串对象参数
                        dataType: "json", //后端返回参数类型
                        success: function (res) { //请求成功后回调函数res = JSONObject.toJSONString(resultMap)
                            if (res.code == 0) {//成功
                                layer.msg(res.msg);//弹出提示
                                table.reload('standard-table'); //数据刷新
                                layer.close(index); //关闭弹层
                            }
                            if (res.code == -1) {//系统出问题
                                layer.msg(res.msg, {icon: 5});//弹出提示
                            }
                        }
                    });
                });
            }else if(obj.event === 'edit'){ //修改
                layer.open({
                    type: 2
                    ,title: '修改'
                    ,skin: 'layui-layer-molv'
                    ,content: 'standard/edit.html'
                    ,maxmin: true
                    ,area: ['1000px', '666px']
                    ,success: function (layero,index){
                        var body = layer.getChildFrame("body",index);
                        body.find("input[name=sal_standard_code]").val(data.sal_standard_code);
                        body.find("input[name=sal_standard_code]").prop('disabled', true); // 设置为不可编辑状态
                        body.find("input[name=sal_standard_name]").val(data.sal_standard_name);
                        body.find("input[name=total]").val(data.total);
                        body.find("input[name=setter]").val(data.setter);
                        body.find("input[name=registrant]").val(data.registrant);
                        var now = new Date(data.register_time);
                        var year = now.getFullYear();  //取得4位数的年份
                        var month = now.getMonth() + 1;  //取得日期中的月份，其中0表示1月，11表示12月
                        var date = now.getDate();      //返回日期月份中的天数（1到31）
                        var register_time = year + "-" + month + "-" + date;
                        body.find("input[name=register_time]").val(register_time);
                        body.find("input[name=basic_salary]").val(data.basic_salary);
                        body.find("input[name=performance]").val(data.performance);
                        body.find("input[name=transportation]").val(data.transportation);
                        body.find("input[name=communication]").val(data.communication);
                        body.find("input[name=meal_subsidy]").val(data.meal_subsidy);
                        body.find("input[name=housing]").val(data.housing);
                        body.find("input[name=business]").val(data.business);
                        body.find("input[name=overtime_subsidy]").val(data.overtime_subsidy);
                    },
                    btn: ['确定', '取消'],
                    yes: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index];
                        var submitID = 'LAY-user-front-submit';
                        var submit = layero.find('iframe').contents().find('#' + submitID);

                        // 监听提交
                        iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                            var field = data.field; // 获取提交的字段
                            // 这里只提交当前行的数据
                            $.ajax({
                                url: "/standard/salEdit", // 请求后端接口地址
                                type: "post", // 请求方式 get | post
                                data: JSON.stringify(field), // 提交json字符串对象参数
                                contentType: "application/json;charset=utf-8", // 发送信息至服务器时内容编码类型
                                dataType: "json", // 后端返回参数类型
                                success: function (res) { // 请求成功后回调函数 res = JSONObject.toJSONString(resultMap)
                                    if (res.code == 0) { // 成功
                                        layer.msg(res.msg); // 弹出提示
                                        table.reload('standard-table'); // 数据刷新
                                        layer.close(index); // 关闭弹层
                                    }
                                    if (res.code == -1) { // 系统出问题
                                        layer.msg(res.msg, {icon: 5}); // 弹出提示
                                    }
                                }
                            });
                        });
                        // 这里不需要触发表单提交事件，而是直接调用提交按钮的点击事件
                        submit.trigger('click');
                    }
                });
            }else if(obj.event === 'review'){ //复核
                layer.open({
                    type: 2
                    ,title: '复核'
                    ,skin: 'layui-layer-molv'
                    ,content: 'standard/review.html'
                    ,maxmin: true
                    ,area: ['1000px', '666px']
                    ,success: function (layero,index){
                        var body = layer.getChildFrame("body",index);
                        body.find("input[name=sal_standard_code]").val(data.sal_standard_code);
                        body.find("input[name=sal_standard_code]").prop('disabled', true); // 设置为不可编辑状态
                        body.find("input[name=sal_standard_name]").val(data.sal_standard_name);
                        body.find("input[name=total]").val(data.total);
                        body.find("input[name=setter]").val(data.setter);
                        body.find("input[name=registrant]").val(data.registrant);
                        body.find("textarea[name=review_comments]").val(data.review_comments);
                        var now = new Date(data.register_time);
                        var year = now.getFullYear();  //取得4位数的年份
                        var month = now.getMonth() + 1;  //取得日期中的月份，其中0表示1月，11表示12月
                        var date = now.getDate();      //返回日期月份中的天数（1到31）
                        var register_time = year + "-" + month + "-" + date;
                        body.find("input[name=register_time]").val(register_time);
                        body.find("input[name=register_time]").val(register_time);
                        body.find("input[name=basic_salary]").val(data.basic_salary);
                        body.find("input[name=performance]").val(data.performance);
                        body.find("input[name=transportation]").val(data.transportation);
                        body.find("input[name=communication]").val(data.communication);
                        body.find("input[name=meal_subsidy]").val(data.meal_subsidy);
                        body.find("input[name=housing]").val(data.housing);
                        body.find("input[name=business]").val(data.business);
                        body.find("input[name=overtime_subsidy]").val(data.overtime_subsidy);
                    }
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        var iframeWindow = window['layui-layer-iframe'+ index]
                            ,submitID = 'LAY-user-front-submit'
                            ,submit = layero.find('iframe').contents().find('#'+ submitID);
                        //监听提交
                        iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                            var field = data.field; //获取提交的字段
                            $.ajax({
                                url:"/standard/salReview", //请求后端接口地址
                                type:"post", //请求方式get | post
                                data:JSON.stringify(field), //提交json字符串对象参数
                                contentType:"application/json;charset=utf-8", //发送信息至服务器时内容编码类型
                                dataType:"json", //后端返回参数类型
                                success:function (res){ //请求成功后回调函数res = JSONObject.toJSONString(resultMap)
                                    if(res.code == 0){//成功
                                        layer.msg(res.msg);//弹出提示
                                        table.reload('standard-table'); //数据刷新
                                        layer.close(index); //关闭弹层
                                    }
                                    if(res.code == -1){//系统出问题
                                        layer.msg(res.msg,{icon: 5});//弹出提示
                                    }
                                }
                            })
                        });
                        submit.trigger('click');
                    }
                });
            }else if(obj.event === 'change'){ //变更
                layer.open({
                    type: 2
                    ,title: '更变'
                    ,skin: 'layui-layer-molv'
                    ,content: 'standard/change.html'
                    ,maxmin: true
                    ,area: ['1000px', '666px']
                    ,success: function (layero,index){
                        var body = layer.getChildFrame("body",index);
                        body.find("input[name=sal_standard_code]").val(data.sal_standard_code);
                        body.find("input[name=sal_standard_code]").prop('disabled', true); // 设置为不可编辑状态
                        body.find("input[name=sal_standard_name]").val(data.sal_standard_name);
                        body.find("input[name=total]").val(data.total);
                        body.find("input[name=setter]").val(data.setter);
                        body.find("input[name=registrant]").val(data.registrant);
                        body.find("textarea[name=reason_change]").val(data.reason_change);
                        var now = new Date(data.register_time);
                        var year = now.getFullYear();  //取得4位数的年份
                        var month = now.getMonth() + 1;  //取得日期中的月份，其中0表示1月，11表示12月
                        var date = now.getDate();      //返回日期月份中的天数（1到31）
                        var register_time = year + "-" + month + "-" + date;
                        body.find("input[name=register_time]").val(register_time);
                        body.find("input[name=register_time]").val(register_time);
                        body.find("input[name=basic_salary]").val(data.basic_salary);
                        body.find("input[name=performance]").val(data.performance);
                        body.find("input[name=transportation]").val(data.transportation);
                        body.find("input[name=communication]").val(data.communication);
                        body.find("input[name=meal_subsidy]").val(data.meal_subsidy);
                        body.find("input[name=housing]").val(data.housing);
                        body.find("input[name=business]").val(data.business);
                        body.find("input[name=overtime_subsidy]").val(data.overtime_subsidy);
                    }
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        var iframeWindow = window['layui-layer-iframe'+ index]
                            ,submitID = 'LAY-user-front-submit'
                            ,submit = layero.find('iframe').contents().find('#'+ submitID);
                        //监听提交
                        iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                            var field = data.field; //获取提交的字段
                            $.ajax({
                                url:"/standard/salChange", //请求后端接口地址
                                type:"post", //请求方式get | post
                                data:JSON.stringify(field), //提交json字符串对象参数
                                contentType:"application/json;charset=utf-8", //发送信息至服务器时内容编码类型
                                dataType:"json", //后端返回参数类型
                                success:function (res){ //请求成功后回调函数res = JSONObject.toJSONString(resultMap)
                                    if(res.code == 0){//成功
                                        layer.msg(res.msg);//弹出提示
                                        table.reload('standard-table'); //数据刷新
                                        layer.close(index); //关闭弹层
                                    }
                                    if(res.code == -1){//系统出问题
                                        layer.msg(res.msg,{icon: 5});//弹出提示
                                    }
                                }
                            })
                        });
                        submit.trigger('click');
                    }
                });
            }else if(obj.event === 'details'){ //明细
                layer.open({
                    type: 2
                    ,title: '明细'
                    ,skin: 'layui-layer-molv'
                    ,content: 'standard/details.html'
                    ,maxmin: true
                    ,area: ['1000px', '666px']
                    ,success: function (layero,index){
                        var body = layer.getChildFrame("body",index);
                        var contentWindow = layero.find('iframe')[0].contentWindow;//得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        body.find("input[name=sal_standard_code]").val(data.sal_standard_code);
                        body.find("input[name=sal_standard_name]").val(data.sal_standard_name);
                        body.find("input[name=total]").val(data.total);
                        body.find("input[name=setter]").val(data.setter);
                        body.find("input[name=registrant]").val(data.registrant);
                        var now = new Date(data.register_time);
                        var year = now.getFullYear();  //取得4位数的年份
                        var month = now.getMonth() + 1;  //取得日期中的月份，其中0表示1月，11表示12月
                        var date = now.getDate();      //返回日期月份中的天数（1到31）
                        var register_time = year + "-" + month + "-" + date;
                        body.find("input[name=register_time]").val(register_time);
                        body.find("input[name=register_time]").val(register_time);
                        body.find("input[name=basic_salary]").val(data.basic_salary);
                        body.find("input[name=performance]").val(data.performance);
                        body.find("input[name=transportation]").val(data.transportation);
                        body.find("input[name=communication]").val(data.communication);
                        body.find("input[name=meal_subsidy]").val(data.meal_subsidy);
                        body.find("input[name=housing]").val(data.housing);
                        body.find("input[name=business]").val(data.business);
                        body.find("input[name=overtime_subsidy]").val(data.overtime_subsidy);
                        var body = layer.getChildFrame("body", index);
                        var inputs = body.find("input"); // 获取所有input元素
                        inputs.prop('readonly', true); // 设置所有input元素为只读

                    }

                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        var iframeWindow = window['layui-layer-iframe'+ index]
                            ,submitID = 'LAY-user-front-submit'
                            ,submit = layero.find('iframe').contents().find('#'+ submitID);
                        //监听提交
                        iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                            var field = data.field; //获取提交的字段
                            $.ajax({
                                url:"/standard/salDetails", //请求后端接口地址
                                type:"post", //请求方式get | post
                                data:JSON.stringify(field), //提交json字符串对象参数
                                contentType:"application/json;charset=utf-8", //发送信息至服务器时内容编码类型
                                dataType:"json", //后端返回参数类型
                                success:function (res){ //请求成功后回调函数res = JSONObject.toJSONString(resultMap)
                                    if(res.code == 0){//成功
                                        layer.msg(res.msg);//弹出提示
                                        table.reload('standard-table'); //数据刷新
                                        layer.close(index); //关闭弹层
                                    }
                                    if(res.code == -1){//系统出问题
                                        layer.msg(res.msg,{icon: 5});//弹出提示
                                    }
                                }
                            })// 在success回调函数中的内容加载完成后
                        });
                        submit.trigger('click');
                    }
                });
            }
        });
    })
</script>
</html>